package com.lzy.masshappy.model.resp;

import com.lzy.masshappy.common.enums.RespCodeEnum;
import lombok.Data;

@Data
public class R {
    private int code;
    private String message;
    private Object data;

    public R putCode(int code) {
        setCode(code);
        return this;
    }

    public R putMessage(String message) {
        setMessage(message);
        return this;
    }

    public R putData(Object data) {
        setData(data);
        return this;
    }

    public static R success () {
        return new R().putCode(RespCodeEnum.SUCCESS.getCode()).putMessage("success");
    }

    public static R success (Object data) {
        return new R().putCode(RespCodeEnum.SUCCESS.getCode()).putMessage("success").putData(data);
    }

    public static R fail (int code, String message) {
        return new R().putCode(code).putMessage(message);
    }

    public static R fail (RespCodeEnum respCodeEnum) {
        return new R().putCode(respCodeEnum.getCode()).putMessage(respCodeEnum.getMessage());
    }
}
